@extends('admin.public.master')
@section('content')
    <div class="content-wrapper">
        <div class="content-wrapper-before"></div>
        <div class="content-header row">
            <div class="content-header-left col-md-1 col-4 mb-2">
                <a href="{{route('attribute.attribute.index')}}"><h5 class="content-header-title">属性列表</h5></a>
            </div>
            <div class="content-header-left col-md-1 col-4 mb-2">
                <a href="{{route('attribute.attribute.create')}}"> <h5 class="content-header-title">添加属性</h5></a>
            </div>
            <div class="content-header-left col-md-1 col-4 mb-2">
                <h5 class="content-header-title">编辑属性</h5>
            </div>

        </div>
        <form action="{{route('attribute.attribute.update',$attribute)}}" method="post">
            @csrf @method('PUT')
            <div class="content-body">
                <div class="card">
                    <div class="card-body">
                        <div class="row">
                            <div class="col-6">
                                <div class="form-group">
                                    <label for="">属性名称</label>
                                    <input type="text" class="form-control" name="name" value="{{$attribute->name}}" aria-describedby="helpId" placeholder="">
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-6">
                                <div class="form-group">
                                    <label for="">父级属性</label>
                                    <select class="form-control" name="pid" id="classify">
                                        <option pid="0" value="0">顶级属性</option>
                                        @foreach($attrs as $item)
                                            <option pid="{{$item->pid}}"  value="{{$item->id}}">{{$item->name}}</option>
                                        @endforeach
                                    </select>
                                </div>
                            </div>
                        </div>
                        {{--<div id="attribute" style="display: none" class="row">--}}
                            {{--<div class="col-6">--}}
                                {{--@foreach($attrs as $attr)--}}
                                    {{--<div class="form-check form-check-inline">--}}
                                        {{--<input name="attribute[]" class="form-check-input" type="checkbox" id="{{$attr['id']}}" value="{{$attr['id']}}">--}}
                                        {{--<label class="form-check-label" for="{{$attr['id']}}">{{$attr->name}}</label>--}}
                                    {{--</div>--}}
                                {{--@endforeach--}}
                            {{--</div>--}}
                        {{--</div>--}}
                    </div>
                    <div class="card-footer text-muted " >
                        <button type="submit" class="btn btn-primary ">保存数据</button>
                    </div>
                </div>
            </div>
        </form>
    </div>

@endsection
@push('js')
    <script>
        $('#classify').change(function () {
            var value= $(this).find('option:checked').attr('pid');
            if (value==0){
                $('#attribute').hide();
            } else{
                $('#attribute').show();

            }

        })
    </script>
@endpush
